package com.example.chat.server.config;

import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

@Configuration
public class NettyConfig {

    /**
     * 存储每一个客户端连接的Channel对象
     */
    @Bean
    public ChannelGroup channelGroup() {
        return new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    }

    /**
     * 存储用户与Channel的对应关系
     */
    @Bean
    public ConcurrentMap<String, Channel> userChannelMap() {
        return new ConcurrentHashMap<>();
    }
}